import { createRouter, createWebHashHistory } from "vue-router"
import useUserStore from "@/store/module/user"

// import Layout from '@/components/HelloWorld.vue'
import { constantRoute } from "./routes"

const router = createRouter({
    history: createWebHashHistory(),
    routes: constantRoute
})

// // 设置路由守卫，解决页面刷新路由丢失问题
router.beforeEach(async (to, from, next) => {


    // 解决页面刷新白屏的问题（刷新页面需要重新添加动态路由）
    if (to.matched?.length === 0) {
        const userStore = useUserStore()
        userStore.genRoutes()
        next({ ...to, replace: true })
    } else {
        next()
    }
})
export default router
